| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | List of all members
nkTasks::Scheduler Class Referencefinal

Manages a ThreadPool and eases the synchronization with the managing thread. More...

## Public Member Functions
| Scheduler (unsigned int threadCount=0) noexcept
| ~Scheduler ()
unsigned int | getThreadCount () const
Thread * | getThread (unsigned int index) const
void | addTask (nkMemory::UniquePtr< SchedulerTask > task)
void | resolveTask (nkMemory::UniquePtr< SchedulerTask > task)
void | cancelPendingTasks ()
void | tick ()
void | flush ()
void | resizeForThreadCount (unsigned int threadCount)

## Detailed Description

Manages a ThreadPool and eases the synchronization with the managing thread.

## Constructor & Destructor Documentation

## ◆ Scheduler()

nkTasks::Scheduler::Scheduler | ( | unsigned int | threadCount = `0` | ) |
| noexcept

Constructor.

Parameters

  threadCount | The number of thread wanted to populate the scheduler's pool.

## ◆ ~Scheduler()

nkTasks::Scheduler::~Scheduler | ( |  | ) |

Destructor.

## Member Function Documentation

## ◆ getThreadCount()

unsigned int nkTasks::Scheduler::getThreadCount | ( |  | ) | const

Returns
  The number of thread in thie scheduler's pool.

## ◆ getThread()

Thread* nkTasks::Scheduler::getThread | ( | unsigned int | index | ) | const

Parameters

  index | The index in the pool of wanted thread.

Returns
  The thread at given index if available, nullptr if unavailable.

## ◆ addTask()

void nkTasks::Scheduler::addTask | ( | nkMemory::UniquePtr< SchedulerTask > | task | ) |

Submit a task to the scheduler.

Parameters

  task | Task to submit.

## ◆ resolveTask()

void nkTasks::Scheduler::resolveTask | ( | nkMemory::UniquePtr< SchedulerTask > | task | ) |

Allows to mark a task as resolved and trigger its post execution callbacks later during the tick method call.

Parameters

  task | The task to resolve.

Remarks
  Called by the threads in scheduler's pool to signal they are ready.

## ◆ cancelPendingTasks()

void nkTasks::Scheduler::cancelPendingTasks | ( |  | ) |

Cancels the pending tasks. See ThreadPool::cancelPendingTasks.

## ◆ tick()

void nkTasks::Scheduler::tick | ( |  | ) |

Ticking function for execution. This should be called within the managing thread, which will call the task's onSync methods through this method. Once a thread has finished processing a task, it will mark it as resolved and enqueue it for resolving within the scheduler. This function has to be called to fully resolve tasks that have been marked as ready by the worker threads.

## ◆ flush()

void nkTasks::Scheduler::flush | ( |  | ) |

Flushes all pending work. For more details, see ThreadPool::flush.

Remarks
  Calling this method also internally calls tick to call the onSync method. As such, in most cases, the managing thread should be the one calling this method.

## ◆ resizeForThreadCount()

void nkTasks::Scheduler::resizeForThreadCount | ( | unsigned int | threadCount | ) |

Allows to change the number of threads constituting this scheduler's thread pool.

Parameters

  threadCount | The number of threads that should constitute the pool.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsTasks/Scheduler/Scheduler.h